package com.acme.task6;

public class CommentRemover {
	public static void main(String[] args) {
		String input = "foo //TODO: remove this comment\nbar /* blah-blah\nmwa-ha-ha*/baz";
		
		System.out.printf("%s%n%n%s", input, stripComments(input));
	}

	private static String stripComments(String input) {
		final int n = input.length();
		StringBuilder sb = new StringBuilder(n);
		
		for (int i = 0; i < n; i++) {
			if (input.charAt(i) == '/') {
				if (input.charAt(i+1) == '/') { // oneline comment
					i = input.indexOf('\n', i) + 1;
				} else if (input.charAt(i+1) == '*') { // multiline comment
					i = input.indexOf("*/", i) + 2;
				}
			}
			
			sb.append(input.charAt(i));
		}
		
		return sb.toString();
	}
	
}